
package com.netease.xone.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;

import com.netease.xone.widget.msgbubble.MessageBubbleRender;
import com.netease.xone.widget.msgbubble.RenderSurface;

public class FragmentMessageBubble extends FragmentBase {

    public static FragmentMessageBubble newInstance() {
        return new FragmentMessageBubble();
    }

    RenderSurface mSurface;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mSurface = new RenderSurface(getActivity());
        final MessageBubbleRender render = new MessageBubbleRender(getActivity());
        mSurface.setRender(render);
        mSurface.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                render.onTouch(v, event);
                return false;
            }
        });
        return mSurface;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(isVisibleToUser){
            show();
        }else{
            hide();
        }
    }

    public void hide(){
        if(mSurface != null){
//            mSurface.setWillDraw(false);
          mSurface.setVisibility(View.INVISIBLE);
        }
    }

    public void show(){
        if(mSurface != null){
//            mSurface.setWillDraw(true);
          mSurface.setVisibility(View.VISIBLE);
        }

    }

}
